home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / restracklib_0_2.lha / ResTrackLib / allocate.c next >
C/C++ Source or Header  |  1994-07-31  |  3KB  |  105 lines

  1. /* allocate.c */
  2.  
  3. #include <stdio.h>
  4. #include <exec/memory.h>
  5. #include <clib/exec_protos.h>
  6. #ifdef REGARGS
  7. #   include <pragmas/exec_pragmas.h>
  8. #endif
  9.  
  10. #include "restrack_intern.h"
  11.  
  12.  
  13. /*****************************************************************************
  14.  
  15.     NAME
  16.     __rtl_Allocate -- allocate memory
  17.  
  18.     SYNOPSIS
  19.     APTR __rtl_Allocate( struct MemHeader *freeList, ULONG byteSize,
  20.                 const char * file, int line);
  21.  
  22.     FUNCTION
  23.     Stub for Allocate().
  24.  
  25.     HISTORY
  26.     23. Jul 1994    Optimizer   created
  27.  
  28. ******************************************************************************/
  29.  
  30. APTR __rtl_Allocate( struct MemHeader *freeList, ULONG byteSize,
  31.             const char * file, int line )
  32. {
  33.     APTR mem;
  34.  
  35.     if ( (mem = Allocate (freeList, byteSize)) )
  36.     CHECK_ADD_RN3(RTL_EXEC,RTLRT_Allocate,mem,byteSize,freeList)
  37.  
  38.     return (mem);
  39. } /* __rtl_Allocate */
  40.  
  41.  
  42. /*****************************************************************************
  43.  
  44.     NAME
  45.     __rtl_Deallocate
  46.  
  47.     SYNOPSIS
  48.     void __rtl_Deallocate( struct MemHeader *freeList, APTR memoryBlock,
  49.             ULONG byteSize, const char * file, int line );
  50.  
  51.     FUNCTION
  52.     Stub for FreeMem(). Frees a block of memory allocated by
  53.     __rlt_AllocMem().
  54.  
  55.     HISTORY
  56.     23. Jul 1994    Optimizer   created
  57.  
  58. ******************************************************************************/
  59.  
  60. void __rtl_Deallocate( struct MemHeader *freeList, APTR memoryBlock,
  61.             ULONG byteSize, const char * file, int line )
  62. {
  63.     ResourceNode * node;
  64.  
  65.     if ((node = FindResourceNode1 (memoryBlock)) )
  66.     {
  67.     if (node->Resource != RTLRT_Allocate)
  68.     {
  69.         fprintf (stderr, "ERROR: Deallocate() at %s:%d called for\n",
  70.             file, line);
  71.         PrintResourceNode (node);
  72.     }
  73.     else
  74.     {
  75.         if (node->Long != byteSize)
  76.         {
  77.         fprintf (stderr, "WARNING: Deallocate() at %s:%d called with wrong size\n",
  78.                 file, line);
  79.         }
  80.  
  81.         if (node->Ptr2 == (APTR)freeList)
  82.         {
  83.         Deallocate (freeList, memoryBlock, node->Long);
  84.         RemoveResourceNode (node);
  85.         }
  86.         else
  87.         fprintf (stderr, "ERROR: Deallocate() called for different MemHeader (%s:%d)\n",
  88.                 file, line);
  89.     }
  90.     }
  91.     else
  92.     CHECK_RT_ERROR_OR_CALL2(RTL_EXEC,Deallocate,"(%p, %ld)",memoryBlock,
  93.         byteSize, Deallocate(freeList, memoryBlock, byteSize))
  94.  
  95. } /* __rlt_Deallocate */
  96.  
  97.  
  98. NRT_RET(APTR,Allocate,(struct MemHeader *freeList, ULONG byteSize),(freeList, byteSize))
  99. NRT(Deallocate,(struct MemHeader *freeList, APTR memoryBlock, ULONG byteSize),(freeList,memoryBlock,byteSize))
  100.  
  101.  
  102. /******************************************************************************
  103. *****  ENDE allocate.c
  104. ******************************************************************************/
  105.